package cz.muni.fi.pa165.soccergamesarchive.persistencelayer.daos;

import cz.muni.fi.pa165.soccergamesarchive.businesslayer.dtos.SoccerMatchHeaderDTO;
import cz.muni.fi.pa165.soccergamesarchive.persistencelayer.entities.SoccerMatch;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;

/**
 *
 * @author Ondrej Dubovec
 *
 * <strong>EDITED BY: Michal Ďuriš</strong>
 */
@Local
public interface SoccerMatchDAO {

    /**
     * Adds a new soccer match
     *
     * @param soccerMatch match to be added
     *
     * @throws IllegalArgumentException if parameter is null or does not have
     *                                  valid atribute values
     * @return Soccer match saved to database
     */
    public SoccerMatch addSoccerMatch(SoccerMatch soccerMatch) throws
            RuntimeException;

    /**
     * Edits an existing soccer match
     *
     * @param soccerMatch to be edited
     *
     * @throws IllegalArgumentException if parameter is null, has invalid ID or
     *                                  invalid atribute values
     * @return edited soccer match
     */
    public SoccerMatch changeSoccerMatch(SoccerMatch soccerMatch) throws
            RuntimeException;

    /**
     * Removes an existing soccer match
     *
     * @param soccerMatch to be removed
     *
     * @throws IllegalArgumentException if match does not exist
     */
    public void deleteSoccerMatch(SoccerMatch soccerMatch) throws
            RuntimeException;

    /**
     * Gets all soccer matches from database
     *
     * @return list of all soccer matches
     */
    public List<SoccerMatch> getAllSoccerMatches();

    /**
     * Gets soccer matches from database. The query will get first limit rows,
     * beginning on the index of offset
     *
     * @param offset offset of the first record
     * @param limit  number of queried socker matches
     * @param filterMap
     * @param orderMap
     *
     * @throws IllegalArgumentException if parameter is null or invalid
     * @return list of soccer matches
     */
    public List<SoccerMatch> getLimitedNumberOfMatches(int offset, int limit, Map<String, Object> filterMap, Map<String, Boolean> orderMap)
            throws RuntimeException;

    /**
     * Retrieves all match headers, which fulfills the filter conditions and are
     * in the given range.
     *
     * @param offset    index of first record
     * @param limit     number of retrieved records
     * @param filterMap filter policy for current data retrieval
     * @param orderMap  order policy for current data retrieval
     *
     * @return list of match header in given range and applied policies
     *
     * @throws IllegalArgumentException if offset or limit has incorrect value
     */
    public List<SoccerMatchHeaderDTO> getLimitedNumberOfMatchHeaders(int offset,
                                                                     int limit,
                                                                     Map<String, Object> filterMap,
                                                                     Map<String, Boolean> orderMap)
            throws RuntimeException;

    /**
     * Method apply the filter policy to all soccer matches and then return a
     * number of corresponding matches
     *
     * @param filterMap filter policy for current action
     *
     * @return count of matches corresponding to the current filter policy
     *
     * @throws RuntimeException not possible to execute this action
     */
    public int getFilteredSoccerMatchesCount(Map<String, Object> filterMap)
            throws RuntimeException;

    /**
     * Method apply the filter policy to all soccer matches and then return a
     * number of corresponding unique dates of matches
     *
     * @param filterMap filter policy for current action
     *
     * @return count of unique dates of matches corresponding to the current
     *         filter policy
     *
     * @throws RuntimeException not possible to execute this action
     */
    public int getFilteredMatchHeadersCount(Map<String, Object> filterMap)
            throws RuntimeException;

    /**
     * Gets soccer match with ID given in parameter
     *
     * @param id id of the required match
     *
     * @throws IllegalArgumentException if parameter is null or invalid
     * @return soccer match with given id
     */
    public SoccerMatch getSoccerMatchById(Long id) throws RuntimeException;

    /**
     * Retrieves all soccer matches in a given date.
     *
     * @param date soccer matches date
     *
     * @return all soccer matches in a given date or empty list if no such
     *         soccer match exist
     *
     * @throws IllegalArgumentException if parameter is null
     */
    public List<SoccerMatch> getSoccerMatchesByDate(Date date) throws
            RuntimeException;

}
